package com.wn.service.impl;

import com.wn.bean.Owner;
import com.wn.bean.OwnerQueryDto;
import com.wn.mapper.OwnerMapper;
import com.wn.service.IOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author yellow Docter
 * @date 2024-07-01
 * @desc 蜗牛创想：www.woniuxy.com
 */
@Service
public class OwnerServiceImpl implements IOwnerService {

    @Autowired
    private OwnerMapper ownerMapper;

    @Override
    public List<Owner> listAllOwners(OwnerQueryDto ownerQueryDto) {
        return ownerMapper.selectOwners(ownerQueryDto);
    }

    @Override
    public boolean updateOwnerById(Owner owner) {

        int row = ownerMapper.updateOwnerById(owner);
//        使用java代码 owner 可以实现动态的sql

        /**
         * 修改
         *     owner{
         *         username = 1,
         *         id = 2
         *     }
         *     我们只需要修改 username + id  其他的属性都不需要修改
         *     update owner set username = 1 ,id = 2 where id = xxx
         *     owner{
         *         username = 1,
         *         id = 2,
         *         tel=123
         *     }
         *     update owner set username = 1 ,id = 2,tel = 3 where id = xxx
         *     mybatis 会用标签动态的判断sql
         */

        return row > 0;
    }

    @Override
    public boolean delOwnerByIds(List<Integer> ids) {

        //delete from owner where id in (1,2,3)
        int row = ownerMapper.delOwnerByIds(ids);

        return row > 0 ;
    }

}
